﻿using rehot;
using rehot.plugin;
using System;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            Console.OutputEncoding = Encoding.UTF8;
            using (var a = RehotAssembly.GetDllByType<Program>())
            {
                var prog = a.FindAttribute("AssemblyProduct").Read<string>("Product");
                Console.WriteLine(prog);
            }

            var _enum = HotEnum.LoadByType<TestEnum>();
            var e1 = _enum.New(HotParam.Put(3));
            Console.WriteLine(e1.Name);
            foreach (var item in _enum.AllMembers())
                Console.WriteLine($"{item.Key}: {item.Value}");
            using (var domain = new HotVirtual())
            {
                domain.LoadDLL("./SanlieHash.dll");
                domain.LoadDLL("./yacomp.dll");
                domain.LoadDLL("./ExcelConfig.dll");
                domain.GetContainer().Run(container =>
                {
                    var dll_ec = container.UseDLL("ExcelConfig");
                    var attrs = dll_ec.FindAttributes().ToList();
                    foreach (var id in dll_ec.FindTypesIdByInterface("IExcelConfig"))
                    {
                        Console.WriteLine(id);
                        var t = dll_ec.FindTypeById(id);
                        Console.WriteLine(t.Name);
                    }

                    foreach (var attr in attrs) if (attr.ExistMember("Product")) Console.WriteLine(attr.Read<string>("Product"));
                    using (var test_config = dll_ec.FindType("AppConfigFile").New(HotParam.Put("./test.config.xlsx")))
                    {
                        var test = test_config.Call<string>("Text", HotParam.Put("test"));
                        Console.WriteLine(test);
                        test_config.Call("WriteText", HotParam.Put("test"), HotParam.Put("测试成功!"));
                        test = test_config.Call<string>("Text", HotParam.Put("test"));
                        Console.WriteLine(test);
                    }

                });
            }
            lock (args) while (true) { Monitor.Wait(args, 1000);  break; }
        }
    }
}
